# == Schema Information
# Schema version: 11
#
# Table name: bundlings
#
#  id         :integer(11)     not null, primary key
#  bundle_id  :integer(11)     
#  posting_id :integer(11)     
#  user_id    :integer(11)     
#  position   :integer(11)     
#  current    :boolean(1)      default(TRUE)
#  notes      :string(1024)    
#  created_at :datetime        
#  updated_at :datetime        
#

class Bundling < ActiveRecord::Base
  belongs_to :user
  belongs_to :bundle
  belongs_to :posting
  
  validates_presence_of :user_id
  validates_presence_of :bundle_id
  validates_presence_of :posting_id
  
  before_validation :ensure_user_id
  
  def ensure_user_id
    self.user_id = bundle.user_id if user_id.blank? && bundle
  end
end
